﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using AStar.Wrapper;

namespace AStar.Collections
{
    class OpenList<T> : MyList<T> where T : IComparable
    {
        public override void Add(T addIt)
        {
            if (root == null)
            {
                root = new ListObj<T>(addIt);
            }
            else
            {
                ListObj<T> temp = root;
                bool added = false;
                ListObj<T> temp2 = new ListObj<T>(addIt);
                while (!added)
                {
                    if (addIt.CompareTo(root.Obj) < 0)
                    {
                        temp2.Next = root;
                        root = temp2;
                        added = true;
                    }
                    else if (temp.Next == null || addIt.CompareTo(temp.Next.Obj) < 0)
                    {
                        temp2.Next = temp.Next;
                        temp.Next = temp2;
                        added = true;
                    }
                    else
                    {
                        temp = temp.Next;
                    }
                }
            }
        }
    }
}
